function mapChildren(children, func, context) {
    let res = []
    let list = Array.isArray(children)? children: [children]
    const getCurKey = (item, index) => {
        return `${item.key?`$${item.key}`:index}`
    }
    const flatten = (list, keyPrefix, parentIndex) => {
        list.forEach((element, index) => {
            if(Array.isArray(element)){
                flatten(element, `.${getCurKey(element, index)}`, index)
            } else {
                let tmpRes = func.call(context, element, parentIndex?parentIndex+index:index)
                if(Array.isArray(tmpRes)){
                    tmpRes.forEach((item, idx) => {
                        item.key = `${keyPrefix?`${keyPrefix}:${getCurKey(element, index)}`: `.${getCurKey(element, index)}`}/${`.${getCurKey(item, idx)}`}`
                    })
                } else {
                    tmpRes.key = `${keyPrefix?`${keyPrefix}:${getCurKey(element, index)}`: `.${getCurKey(element, index)}`}/${`.${getCurKey(tmpRes, 0)}`}`
                }
                res = res.concat(tmpRes)
            }
        });
    }
    flatten(list)
    return res;
}

export {
    mapChildren as map,
};